/**
 *   _                                                          _   
 *  | | ____ _ _ __ _ __ ___   __ _  ___           _ __ ___ ___| |_ 
 *  | |/ / _` | '__| '_ ` _ \ / _` |/ __|  _____  | '__/ _ | __| __|
 *  |   < (_| | |  | | | | | | (_| | (__  |_____| | | |  __|__ \ |_ 
 *  |_|\_\__,_|_|  |_| |_| |_|\__,_|\___|         |_|  \___|___/\__|
 *         
 *  Copyright  2011 Kondra, Inc. 
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.kondra.karmac.rest
{
   /**
    * The <code>ServiceRef</code> class is a reference object for an
    * <code>IServiceEndpoint</code> either specified by reference, or
    * as an entry in a <code>ServiceConfig</code> object. 
    * 
    * @author Jared Kaplan
    */  
   public class ServiceRef
   {
      private var m_key:String;
      private var m_config:ServiceConfig;
      private var m_source:*;
      private var m_data:*;
      
      public function ServiceRef( key:String = null, config:ServiceConfig = null, source:* = null, data:* = null ) 
      {
         m_key = key;
         m_config = config;
         m_source = source;
         m_data = data;
      }
      
      /**
       * Returns the <code>IServiceEndpoint</code> istance referenced by this object.
       */ 
      public function getService() : IServiceEndpoint
      {
         var service:IServiceEndpoint = null;
         
         if( source is IServiceEndpoint )
            service = source as IServiceEndpoint;
         
         else if( source is String && config != null )
            service = config.getService( source as String );
         
         return service;
      }
      
      //
      // getter/setter methods
      //
      
      public function set key( key:String ) : void { m_key = key; }
      public function get key() : String { return m_key; }
      
      public function set config( config:ServiceConfig ) : void { m_config = config; }
      public function get config() : ServiceConfig { return m_config; }
      
      public function set source( source:* ) : void { m_source = source; }
      public function get source() : * { return m_source; }
      
      public function set data( data:* ) : void { m_data = data; }
      public function get data() : * { return m_data; }
   }
}